package com.cndw.kungfu.model.operation.domain;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.ext.XmlProcesser;

public class TreeFruit {

	private int type;

	private int level;

	private String name;

	private int rateUp;

	private int rateUpGold;

	private int rateDown;

	private int rateDownGold;

	private static final Map<Integer, TreeFruit> dataMap = new HashMap<Integer, TreeFruit>();

	private static final String configFile = "treeFruit.xml";

	private static final int typeCoef = 100;

	static {
		load();
	}

	public static synchronized void load() {
		String fileName = ConstantsConfig.getLocaleResource() + configFile;
		List<TreeFruit> dataList = XmlProcesser.processXml(TreeFruit.class, fileName);
		if (dataList != null && dataList.size() > 0) {
			for (TreeFruit e : dataList) {
				dataMap.put(e.getType() * typeCoef + e.getLevel(), e);
			}
		}
	}

	public static synchronized void clear() {
		load();
	}

	public static Collection<TreeFruit> getAll() {
		return dataMap.values();
	}

	public static TreeFruit getOne(int type, int level) {
		return dataMap.get(type * typeCoef + level);
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getRateUp() {
		return rateUp;
	}

	public void setRateUp(int rateUp) {
		this.rateUp = rateUp;
	}

	public int getRateUpGold() {
		return rateUpGold;
	}

	public void setRateUpGold(int rateUpGold) {
		this.rateUpGold = rateUpGold;
	}

	public int getRateDown() {
		return rateDown;
	}

	public void setRateDown(int rateDown) {
		this.rateDown = rateDown;
	}

	public int getRateDownGold() {
		return rateDownGold;
	}

	public void setRateDownGold(int rateDownGold) {
		this.rateDownGold = rateDownGold;
	}

}
